const mongoose = require('mongoose');
mongoose
  .connect("mongodb+srv://liulinze678:liulinze041029@cluster0.gspejsd.mongodb.net/")
  .then(() => {
    console.log("连接成功")
  })
  .catch((error) => {
    console.error("连接失败:", error)
  })

const loginSchema = new mongoose.Schema({
  email:String,
  password:String,
  newpassword:String,
  sex:{
    default:'女',
    type:String
  },
  kg:{
    default:'90',
    type:String
  },
  img:{
    default:'../1.png',
    type:String
  },
  name:{
    default:'1514992092@qq.com',
    type:String
  }
})

const loginModel = new mongoose.model("login", loginSchema, "login")

// 商品模型
const productSchema = new mongoose.Schema({
  id: Number,
  name: String,
  price: Number,
  image: String,
  tag: String,
  description: String,
  category: String
})

const productModel = mongoose.model("product", productSchema, "products")

// 分类模型
const categorySchema = new mongoose.Schema({
  id: Number,
  name: String,
  icon: String
})

const categoryModel = mongoose.model("category", categorySchema, "categories")

module.exports = { 
  loginModel,
  productModel,
  categoryModel
}

